﻿#pragma once
#include<algorithm>
#include<vector>

template<typename T>
class stdHeap
{
public:
	void MakeHeap()
	{
		std::make_heap(m_arr.begin(), m_arr.end());
	}
	template<typename CMP>
	void MakeHeap(CMP& compare)
	{
		std::make_heap(m_arr.begin(), m_arr.end(), compare);
	}

	void PushHeap(const T&& t)
	{
		m_arr.push_back(t);
		push_heap(m_arr.begin(), m_arr.end());
	}
	template<typename CMP>
	void PushHeap(const T&& t, CMP& compare)
	{
		m_arr.push_back(t);
		push_heap(m_arr.begin(), m_arr.end(), compare);
	}

	void PopHeap()
	{
		if (!m_arr.empty())
		{
			pop_heap(m_arr.begin(), m_arr.end());
			m_arr.pop_back();
		}
		else
		{
			throw std::bad_alloc;
		}
	}
	template<typename CMP>
	void PopHeap(CMP& compare)
	{
		if (!m_arr.empty())
		{
			pop_heap(m_arr.begin(), m_arr.end(), compare);
			m_arr.pop_back();
		}
		else
		{
			throw std::bad_alloc;
		}
	}

	void Sort()
	{
		sort_heap(m_arr.begin(), m_arr.end());
	}
	template<typename CMP>
	void Sort(CMP& compare)
	{
		sort_heap(m_arr.begin(), m_arr.end(), compare);
	}

	const T& Top()
	{
		return m_arr.at(0);
	}
public:
	std::vector<T>	m_arr;
};